﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class MARCDetails : System.Web.UI.UserControl
{
    public DataTable ds = new DataTable();
    public DataTable TagSet
    {

        get { return ds; }

        set
        {
            ds = value;
          
        }

    }
     public void switching(string tag, string val)
    {
        

        
        switch (tag)
        {
            case "000":
               leader.Text = val;
                break;
            ////////isbn//////////
            case "008":
                fix.Text = val;
                break;
            ////////isbn//////////
            case "100":
                auth.Text = val;
                     break;
            ////////isbn//////////
            case "020":
                     isn.Text = val;
                     break;
            case "022":
                     isn.Text = val;
                     break;
            //////congress//////
            case "050":
                     lc.Text = val;
                     break;
            //////phy//////
            case "300":
                     f300.Text = val;
                     break;
            //////dabt//////
            case "035":
                     f35.Text = val;
                     break;
            //////dewey//////
            case "082":
                     dewey.Text = val;
                     break;
            case "240":
            ////////title//////////
                     address.Text += val;
                     break;

            case "245":
                     address.Text += val;
                     break;
            ///////title//////////
            case "222":
                     address.Text += val;
                     break;
            case "650":
                     //////////////////
                      topics.Text += val;
                     break;
            //////desc////////
            case "500":
                   

                     notes.Text += val;
                     break;
            /////////desc///////
            case "504":
                     notes.Text += val;
                    
                     break;
            /////////desc///////
            case "505":
                     notes.Text += val;
                     break;
            /////////desc///////
            case "530":
                     notes.Text += val;
                     break;
            /////////desc///////
            case "590":
                     //////////////////
                     notes.Text += val;
                     break;
            case "260":
                     
                         pups.Text += val;
                     
                     break;
            ////////////////////////
            default:


                     break;
        }
     }
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            //fields.InnerHtml="<table>";
            //foreach (DataRow dr in ds.Rows)
            //{
            //    string tag=dr["tag"].ToString();
            //    string inds=dr["indicator"].ToString();
            //    string subfield=dr["subfield"].ToString();
            //    string field=dr["field"].ToString();
                
            //    switching(tag,field.Replace('%',' '));

            //    fields.InnerHtml += "<tr><td><h3>" + tag + "</h3></td><td>" + inds + "</td><td>" + field + subfield + "</td></tr>";
            //}
        
        }
    }
    public string fieldconvert(string fld, string subs)
    {

        string[] written = fld.Split('%');
        string[] subfield2 = subs.Split('$');
        string bb = "";
        for (int i = 0; i < written.Length; i++)
        {

            bb += subfield2[i] + "|" + written[i];

        }
        //////////////////////////////////////////////////////
        return bb;
    }
    public void setMarc( DataTable dss)
    {

        address.Text = "";
        topics.Text = "";
        notes.Text = "";
        pups.Text = "";
        /////////////////////////////////////
        fields.InnerHtml = "<table width='100%' dir='rtl'>";
        for (int i = 0; i < dss.Rows.Count - 1; i++)
        {

            string tag = dss.Rows[i]["tag"].ToString();
            string inds = dss.Rows[i]["indicator"].ToString();
            string subfield = dss.Rows[i]["subfield"].ToString();
            string field = dss.Rows[i]["field"].ToString();
            ///////////////////////////////////////////////////

            switching(tag, field.Replace('%', ' '));
            ////////////////////////////////////////////////////////
            field = fieldconvert(field, subfield);
            /////////////////////////////////////////////////////////////
            fields.InnerHtml += "<tr><td class='stylelabel3' style='padding:5px;' >" + tag + "</td><td  style='padding:5px;'>" + inds + "</td><td  style='padding:5px;'>" + field + "</td>";
            if (i < dss.Rows.Count - 1)
            {
                i++;
                tag = dss.Rows[i]["tag"].ToString();
                inds = dss.Rows[i]["indicator"].ToString();
                subfield = dss.Rows[i]["subfield"].ToString();
                field = dss.Rows[i]["field"].ToString();
                switching(tag, field.Replace('%', ' '));
                ////////////////////////////////////////////////////////
                field = fieldconvert(field, subfield);
                /////////////////////////////////////////////////////////////
                fields.InnerHtml += "<td class='stylelabel3' style='padding:5px;'>" + tag + "</td><td  style='padding:5px;'>" + inds + "</td><td  style='padding:5px;' >" + field + "</td>"; //"<td>" + tag + "</td><td>" + inds + "</td><td>" + field +  "</td>";

            }
            if (i < dss.Rows.Count - 1)
            {
                i++;
                tag = dss.Rows[i]["tag"].ToString();
                inds = dss.Rows[i]["indicator"].ToString();
                subfield = dss.Rows[i]["subfield"].ToString();
                field = dss.Rows[i]["field"].ToString();
                switching(tag, field.Replace('%', ' '));
                ////////////////////////////////////////////////////////
                field = fieldconvert(field, subfield);
                /////////////////////////////////////////////////////////////
                fields.InnerHtml += "<td class='stylelabel3' style='padding:5px;'>" + tag + "</td><td  style='padding:5px;'>" + inds + "</td><td  style='padding:5px;'>" + field + "</td>";//"<td>" + tag + "</td><td>" + inds + "</td><td>" + field +  "</td>";

            }

            fields.InnerHtml += "</tr>";





        }
        fields.InnerHtml += "</table>";
    
    }

}
